#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import zmail

# 项目目录
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# 报告文件
REPORT_FILE = os.path.join(BASE_DIR, 'report.html')

# 邮件信息
EMAIL_INFO = {
    'username': '1759073141@qq.com',  # 切换成你自己的地址
    # 'password': 'QQ邮箱授权码',
    'password': 'sbvkrzlwpizheibi',
    'smtp_host': 'smtp.qq.com',
    'smtp_port': 465
}

# 收件人
ADDRESSEE = [
    '1759073141@qq.com',
]


def send_report():
    """发送报告"""
    try:
        with open(REPORT_FILE, encoding='utf-8') as f:
            content_html = f.read()
    except Exception as e:
        print('报告文件不存在')
        return {'msg':'报告文件不存在'}

    try:
        mail = {
            'from': '1759073141@qq.com',
            'subject': '最新的测试报告邮件',
            'content_html': content_html,
            'attachments': [REPORT_FILE, ]
        }
        server = zmail.server(*EMAIL_INFO.values())
        server.send_mail(ADDRESSEE, mail)
        print("测试邮件发送成功！")
    except Exception as e:
        print("Error: 无法发送邮件，{}！", format(e))


if __name__ == "__main__":
    '''请先在config/conf.py文件设置QQ邮箱的账号和密码'''
    send_report()
